<?php

declare(strict_types=1);
/**
 * This file is part of MineAdmin.
 *
 * @link     https://www.mineadmin.com
 * @document https://doc.mineadmin.com
 * @contact  root@imoi.cn
 * @license  https://github.com/mineadmin/MineAdmin/blob/master/LICENSE
 */

namespace App\Schema\Course;

use App\Model\Course;
use Hyperf\Swagger\Annotation\Property;
use Hyperf\Swagger\Annotation\Schema;

#[Schema]
final class CourseSchema implements \JsonSerializable
{
    public ?string $remark;

    public function __construct(
        Course $model,
        #[Property(property: 'title', title: '课题标题', type: 'string')]
        public ?string $title,
        #[Property(property: 'introduce', title: '课程简介', type: 'string')]
        public ?string $introduce,
        #[Property(property: 'score_option', title: '分数配置', type: 'string')]
        public ?string $score_option,
        #[Property(property: 'thumb', title: '封面', type: 'string')]
        public ?string $thumb,
        #[Property(property: 'is_publish', title: '是否发布', type: 'string')]
        public ?int $is_publish
    ) {

        foreach (
            get_class_vars(__CLASS__)
            as $var
        ) {
            $this->{$var} = $model->${$var};
        }
    }

    public function jsonSerialize(): mixed
    {
        $json = [];
        foreach (
            get_class_vars(__CLASS__)
            as $var
        ) {
            $json[$var] = $this->{$var};
        }
        return $json;
    }
}
